package com.itheima.service.impl;

import com.itheima.dao.SysJobDao;
import com.itheima.pojo.SysJob;
import com.itheima.service.SysJobService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (SysJob)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("sysJobService")
public class SysJobServiceImpl implements SysJobService {
    @Resource
    private SysJobDao sysJobDao;

    /**
     * 通过ID查询单条数据
     *
     * @param jobId 主键
     * @return 实例对象
     */
    @Override
    public SysJob queryById(Long jobId) {
        return this.sysJobDao.queryById(jobId);
    }

    /**
     * 分页查询
     *
     * @param sysJob 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SysJob> queryByPage(SysJob sysJob, PageRequest pageRequest) {
        long total = this.sysJobDao.count(sysJob);
        return new PageImpl<>(this.sysJobDao.queryAllByLimit(sysJob, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param sysJob 实例对象
     * @return 实例对象
     */
    @Override
    public SysJob insert(SysJob sysJob) {
        this.sysJobDao.insert(sysJob);
        return sysJob;
    }

    /**
     * 修改数据
     *
     * @param sysJob 实例对象
     * @return 实例对象
     */
    @Override
    public SysJob update(SysJob sysJob) {
        this.sysJobDao.update(sysJob);
        return this.queryById(sysJob.getJobId());
    }

    /**
     * 通过主键删除数据
     *
     * @param jobId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long jobId) {
        return this.sysJobDao.deleteById(jobId) > 0;
    }
}
